﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace OnlineStore.Business_Logic_Layer
{
    class BizImport : OnlineStore.BisTrans
    {
        public bool ValidateData(DataGridViewRowCollection PurchaseDetail)
        {
            return true;
        }
        public int SaveImport(int nPurchaseID, DataGridViewRowCollection PurchaseDetail, string strTranDate)
        {
            try
            {
                int nResult = 0;
                BizProduct eBizProduct = new BizProduct();
                for (int i = 0; i < PurchaseDetail.Count; i++)
                {
                    // Update stock on store
                    eBizProduct.UpdatePurchasetoStockProduct(int.Parse(PurchaseDetail[i].Cells[2].Value.ToString()),int.Parse(PurchaseDetail[i].Cells[1].Value.ToString()), int.Parse(PurchaseDetail[i].Cells[0].Value.ToString()));
                    // Save in to transaction
                    nResult += SaveTransaction(strTranDate, PurchaseDetail[i].Cells[2].Value.ToString(), int.Parse(PurchaseDetail[i].Cells[0].Value.ToString()), nPurchaseID.ToString());
                }
                return nResult;

            }
            catch (Exception ex)
            {
                ex.ToString();
                return -1;
            }
            return -1;
        }
    
    }
}
